<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Works extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('works', ['engine' => 'MyISAM']);

        $table->addColumn('title', 'string', ['limit' => 45, 'null' => TRUE, 'comment' => '标题'])
            ->addColumn('column_id', 'integer', ['limit' => 6, 'null' => FALSE, 'comment' => '栏目ID'])
            ->addColumn('keywords', 'string', ['limit' => 30, 'null' => FALSE, 'comment' => '关键词'])
            ->addColumn('description', 'string', ['limit' => 255, 'null' => true, 'comment' => '描述'])
            ->addColumn('author', 'string', ['limit' => 20, 'null' => true, 'comment' => '作者'])
            ->addColumn('pic', 'string', ['limit' => 255, 'null' => true, 'comment' => '缩略图'])
            ->addColumn('source', 'string', ['limit' => 255, 'null' => true, 'comment' => '来源'])
            ->addColumn('content', 'text', ['null' => false, 'comment' => '内容'])
            ->addColumn('istop', 'integer', ['limit'=>1,'default' => 0, 'comment' => '是否置顶'])
            ->addColumn('isopen', 'integer', ['limit'=>1,'default' => 0, 'comment' => '是否公开'])
            ->addColumn('hits', 'integer', ['limit'=>8,'default' => 0, 'comment' => '点击数'])
            ->addColumn('status', 'integer', ['limit'=>1,'default' => 0, 'comment' => '状态'])
            ->addColumn('create_time', 'integer', ['limit'=>11,'null'=>true, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'=>11,'null'=>true, 'comment' => '修改时间'])
            ->addColumn('delete_time', 'integer', ['limit'=>11,'null'=>true, 'comment' => '软删除'])
            ->addIndex(array('title'), array('unique' => true))
            ->create();
    }
}
